<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="formObject"
      label-width="100px"
      :rules="rules"
      status-icon
      label-position="left"
    >
      <el-dropdown
        style="position: absolute; right: 50px; top: 20px; z-index: 10"
        trigger="click"
        @command="handleCommand"
      >
        <el-button size="small" type="primary">
          选单<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="salesContract">销售合同</el-dropdown-item>
          <el-dropdown-item command="saleOrder">销售订单</el-dropdown-item>
          <el-dropdown-item command="2">销售报价单</el-dropdown-item>
          <el-dropdown-item command="3">物料清单</el-dropdown-item>
          <el-dropdown-item command="4">采购订单</el-dropdown-item>
          <el-dropdown-item command="5">网上订单</el-dropdown-item>
          <el-dropdown-item command="6">预测单</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-collapse v-model="activeName" @change="handleClick">
        <el-collapse-item title="销售订单" name="saleOrderEntity">
          <div class="desc-title">基本信息</div>
          <el-row :gutter="15">
            <el-col v-if="rowId" :span="8">
              <el-form-item label="单据类型" prop="docType">
                <el-input
                  :disabled="true"
                  style="width: 100%"
                  v-model="formObject.docType"
                  :props="props"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col v-if="!rowId" :span="8">
              <el-form-item label="单据类型" prop="docType">
                <el-cascader
                  style="width: 100%"
                  v-model="formObject.docType"
                  :props="props"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="单据编码" prop="saleOrderEntity.kingDocCode">
                <el-input
                  v-model="formObject.saleOrderEntity.kingDocCode"
                  placeholder="请输入单据编码"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="日期" prop="saleOrderEntity.saleDate">
                <el-date-picker
                  v-model="formObject.saleOrderEntity.saleDate"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :style="{ width: '100%' }"
                  placeholder="请输入日期"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
              <el-form-item
                label="业务类型"
                prop="saleOrderEntity.businessType"
              >
                <el-select
                  v-model="formObject.saleOrderEntity.businessType"
                  placeholder="请输入业务类型"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in businessTypeOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="8">
              <el-form-item
                label="交货方式"
                prop="saleOrderEntity.deliveryMethod"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.deliveryMethod"
                  placeholder="请输入交货方式"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="交货地点"
                prop="saleOrderEntity.deliveryAddress"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.deliveryAddress"
                  placeholder="请输入交货地点"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户" prop="saleOrderEntity.customerName">
                <el-input
                  v-model="formObject.saleOrderEntity.customerName"
                  placeholder="请输入客户"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('customer')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="价目表" prop="saleOrderEntity.priceinfoId">
                <el-input
                  v-model="formObject.saleOrderEntity.priceinfoId"
                  placeholder="请输入价目表"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="收款条件"
                prop="saleOrderEntity.paymentTermsTitle"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.paymentTermsTitle"
                  placeholder="请输入收款条件"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('paymentTerms')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="是否含税" prop="saleOrderEntity.priceTax">
                <el-select
                  v-model="formObject.saleOrderEntity.priceTax"
                  placeholder="请选择是否含税"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in priceTaxOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="销售部门"
                prop="saleOrderEntity.saleDeptName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.saleDeptName"
                  placeholder="请输入销售部门"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('saleDept')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="销售组" prop="saleOrderEntity.saleGroup">
                <el-input
                  v-model="formObject.saleOrderEntity.saleGroup"
                  placeholder="请输入销售组"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="销售员" prop="saleOrderEntity.saleName">
                <el-input
                  v-model="formObject.saleOrderEntity.saleName"
                  placeholder="请输入销售员"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('saleId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="desc-title">客户信息</div>
          <el-row :gutter="15">
            <el-col :span="8">
              <el-form-item
                label="收货方"
                prop="saleOrderEntity.receivingPartyName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.receivingPartyName"
                  placeholder="请选择收货方"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('receivingParty')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="结算方"
                prop="saleOrderEntity.settlementPartyName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.settlementPartyName"
                  placeholder="请输入结算方"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('settlementParty')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="付款方" prop="saleOrderEntity.payerName">
                <el-input
                  v-model="formObject.saleOrderEntity.payerName"
                  placeholder="请输入付款方"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('payer')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="收获联系人"
                prop="saleOrderEntity.shippingPerson"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.shippingPerson"
                  placeholder="请输入收获联系人"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="收货人姓名"
                prop="saleOrderEntity.shippingPersonName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.shippingPersonName"
                  placeholder="请输入收货人姓名"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="联系人方式"
                prop="saleOrderEntity.shippingPhone"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.shippingPhone"
                  placeholder="请输入联系人方式"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="收货地址"
                prop="saleOrderEntity.shippingAddress"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.shippingAddress"
                  placeholder="请输入收货地址"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="desc-title">财务信息</div>
          <el-row :gutter="15">
            <el-col :span="8">
              <el-form-item
                label="结算币别"
                prop="saleOrderEntity.currencyName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.currencyName"
                  placeholder="请输入结算币别"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('currency')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="结算方式"
                prop="saleOrderEntity.settlementTypeName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.settlementTypeName"
                  placeholder="请输入结算方式"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('settlementType')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="价目表"
                prop="saleOrderEntity.priceinfoIdName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.priceinfoIdName"
                  placeholder="请输入价目表"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('priceinfoId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="折扣表"
                prop="saleOrderEntity.discountInfoIdName"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.discountInfoIdName"
                  placeholder="请输入折扣表"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('discountInfoId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="税额" prop="saleOrderEntity.taxAmount">
                <el-input
                  v-model="formObject.saleOrderEntity.taxAmount"
                  placeholder="请输入税额"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="金额" prop="saleOrderEntity.valueTax">
                <el-input
                  v-model="formObject.saleOrderEntity.valueTax"
                  placeholder="请输入金额"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="保证金比例%"
                prop="saleOrderEntity.marginLevel"
              >
                <el-input
                  v-model="formObject.saleOrderEntity.marginLevel"
                  placeholder="请输入保证金比例%"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="保证金" prop="saleOrderEntity.margin">
                <el-input
                  v-model="formObject.saleOrderEntity.margin"
                  placeholder="请输入保证金"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="汇率类型" prop="saleOrderEntity.rateType">
                <el-input
                  v-model="formObject.saleOrderEntity.rateType"
                  placeholder="请输入汇率类型"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('rateType')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="是否含税" prop="saleOrderEntity.isTax">
                <el-radio-group
                  v-model="formObject.saleOrderEntity.isTax"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in isTaxOptions"
                    :key="index"
                    :label="item.value"
                    :disabled="item.disabled"
                    border
                    >{{ item.label }}</el-radio
                  >
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="订单条款" name="orderPurchaseTerms">
          <el-table
            :data="formObject.orderPurchaseTerms"
            style="width: 100%"
            highlight-current-row
            border
          >
            <template #empty>
              <el-button
                plain
                type="primary"
                round
                @click="addNewRow('orderPurchaseTerms')"
                >添加新行
              </el-button>
            </template>
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="addOrderPurchaseTerms(scope.$index, scope.row)"
                ></el-button>
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'orderPurchaseTerms'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column label="采购订单">
              <template slot-scope="scope">
                <el-form-item
                  prop="orderId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.orderId"> </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="采购条款">
              <template slot-scope="scope">
                <el-form-item
                  prop="purchaseTermsId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.purchaseTermsId"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="关联类型">
              <template slot-scope="scope">
                <el-form-item prop="type" label-width="0px" style="margin: 0">
                  <el-select
                    v-model="scope.row.type"
                    placeholder="请选择"
                    style="width: 100%"
                  >
                    <el-option key="0" label="采购订单" value="0"></el-option>
                    <el-option key="1" label="销售订单" value="1"></el-option>
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="创建人">
              <template slot-scope="scope">
                <el-form-item prop="userId" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.userId"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="描述">
              <template slot-scope="scope">
                <el-form-item
                  prop="describe"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.describe" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="物流跟踪" name="saleOrderLogisticsEntities">
          <el-table
            :data="formObject.saleOrderLogisticsEntities"
            style="width: 100%"
            highlight-current-row
            border
          >
            <template #empty>
              <el-button
                plain
                type="primary"
                round
                @click="addNewRow('saleOrderLogisticsEntities')"
                >添加新行
              </el-button>
            </template>
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="
                    addSaleOrderLogisticsEntities(scope.$index, scope.row)
                  "
                ></el-button>
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'saleOrderLogisticsEntities'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column label="物流公司">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.logisticsCompany"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.logisticsCompany"> </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="物流单号">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.logisiticsNumber"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.logisiticsNumber"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="类型">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.type"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.type"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="物流状态">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.logisticsState"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.logisticsState"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="发货时间">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.deliveryTime"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.deliveryTime"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="签收时间">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.signTime"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.signTime" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="起始地点">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.startAddress"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.startAddress"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="终止地点">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.endAddress"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.endAddress" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="寄件人手机号">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderLogisticsEntities.senderPhone"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.senderPhone"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="交货明细" name="saleOrderDeliveryEntity">
          <el-row :gutter="15">
            <el-col :span="8">
              <el-form-item
                label="物料编码"
                prop="saleOrderDeliveryEntity.materialCode"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.materialCode"
                  placeholder="请输入物料编码"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="物料名称"
                prop="saleOrderDeliveryEntity.materialName"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.materialName"
                  placeholder="请输入物料名称"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="库存组织"
                prop="saleOrderDeliveryEntity.inventoryDept"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.inventoryDept"
                  placeholder="请输入库存组织"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="	发货上限"
                prop="saleOrderDeliveryEntity.deliveryUp"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.deliveryUp"
                  placeholder="请输入发货上限"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="发货下限"
                prop="saleOrderDeliveryEntity.deliveryDown"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.deliveryDown"
                  placeholder="请输入发货下限"
                  clearable
                  :style="{ width: '100%' }"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="超发控制单位类型"
                prop="saleOrderDeliveryEntity.deliveryType"
                label-width="130px"
              >
                <el-select
                  v-model="formObject.saleOrderDeliveryEntity.deliveryType"
                  placeholder="请选择超发控制单位类型"
                  clearable
                  :style="{ width: '100%' }"
                >
                  <el-option key="0" label="销售单位" value="0"></el-option>
                  <el-option key="1" label="库存单位" value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label="超发控制单位"
                prop="saleOrderDeliveryEntity.deliveryUnit"
              >
                <el-input
                  v-model="formObject.saleOrderDeliveryEntity.deliveryUnit"
                  placeholder="请输入超发控制单位"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="desc-title">交货明细详情</div>
          <el-table
            :data="formObject.saleOrderDeliveryDetailEntities"
            style="width: 100%"
            highlight-current-row
            border
          >
            <template #empty>
              <el-button
                plain
                type="primary"
                round
                @click="addNewRow('saleOrderDeliveryDetailEntities')"
                >添加新行
              </el-button>
            </template>
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="
                    addSaleOrderDeliveryDetailEntities(scope.$index, scope.row)
                  "
                ></el-button>
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'saleOrderLogisticsEntities'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column label="交货明细">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.deliveryId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.deliveryId"> </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="交货地点">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.deliveryAddress"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.deliveryAddress"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="交货地址">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.deliveryAddressDetail"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.deliveryAddressDetail"
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="要货日期">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.deliveryDate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.deliveryDate"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="运输提前期">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.inAdvance"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.inAdvance"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计划发货日期">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.planDeliveryDate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.planDeliveryDate"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="销售单位">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.saleUnit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.saleUnit" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleOrderDeliveryDetailEntities.saleNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.saleNum" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="物料明细" name="materialDetailEntities">
          <el-button type="text" @click="addNewRow('materialDetailEntities')"
            >新增行</el-button
          >
          <el-table
            :data="formObject.materialDetailEntities"
            style="width: 100%"
            highlight-current-row
            border
          >
            <el-table-column label="操作" width="60">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'materialDetailEntities'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column width="200" label="物料编码">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.materialCode"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    @focus="addDialog('material', scope.$index)"
                    v-model="scope.row.materialCode"
                  >
                    <i
                      slot="suffix"
                      @click="addDialog('material', scope.$index)"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="物料名称">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.materialName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.materialName"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="库存数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.inventoryNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.inventoryNum"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计价单位">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.pricingUnit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.pricingUnit"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计价数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.pricingNum"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="单价">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.price"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.price"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="含税单价">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.taxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxPrice"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="是否赠品">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.isGiveaway"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-checkbox
                    :disabled="scope.row.isGiveaway"
                    :v-model="scope.row.isGiveaway"
                    clearable
                  ></el-checkbox>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="税率">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.taxRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxRate"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="税额">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.taxAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.amountMoney"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.amountMoney"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="价税合计">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.totalTaxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.totalTaxPrice"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="价税合计">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.totalTaxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.totalTaxPrice"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="库存">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.inventoryId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.inventoryId"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="结算组织">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.settlementDept	"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.settlementDept"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="备注">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialDetailEntities.ramarks	"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.ramarks"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="收款计划" name="saleCollectionPlanEntities">
          <el-table
            :data="formObject.saleCollectionPlanEntities"
            style="width: 100%"
            highlight-current-row
            border
          >
            <template #empty>
              <el-button
                plain
                type="primary"
                round
                @click="addNewRow('saleCollectionPlanEntities')"
                >添加新行
              </el-button>
            </template>
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="
                    addSaleCollectionPlanEntities(scope.$index, scope.row)
                  "
                ></el-button>
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'saleCollectionPlanEntities'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column label="是否预收">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.isPreReceipt"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.isPreReceipt"> </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="应收比例">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.receivableRatio"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.receivableRatio"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="应收金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.receivableAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.receivableAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="到期日">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.dueTime"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-date-picker
                    v-model="scope.row.dueTime"
                    type="datetime"
                    placeholder="选择到期日"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    format="yyyy-MM-dd HH:mm:ss"
                    style="width: 100%"
                  >
                  </el-date-picker>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="关联单号">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.associationOrderNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.associationOrderNum"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="实收金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.netReceiptsAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.netReceiptsAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="控制环节">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.controlLink"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.controlLink"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="预收超出金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.excessAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.excessAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="实际预收发货">
              <template slot-scope="scope">
                <el-form-item
                  prop="saleCollectionPlanEntities.actualPrepaymentDelivery"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.actualPrepaymentDelivery"
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialog"
      append-to-body
      width="70%"
      destroy-on-close
      v-if="dialog"
    >
      <component
        :is="currentCom"
        :id="rowId"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      ></component>
    </el-dialog>
  </div>
</template>
<script>
import { listDept } from "@/api/system/dept";
import { getAreaList } from "@/api/area/area";
import { getOrderDetail, addList, getDocTypeList } from "@/api/system/purchase";
import { addSaleList } from "@/api/system/sale";
import Customer from "./dialog/customer";
import Currency from "./dialog/currency";
import PriceinfoId from "./dialog/priceinfoId";
import PaymentTerms from "./dialog/paymentTerms";
import SaleDept from "./dialog/saleDept";
import SaleId from "./dialog/saleId";
import SettlementType from "./dialog/settlementType";
import DiscountInfoId from "./dialog/discountInfoId";
import RateType from "./dialog/rateType";
import ReceivingParty from "./dialog/receivingParty";
import SettlementParty from "./dialog/settlementParty";
import salesContract from "./dialog/salesContract";
import Payer from "./dialog/payer";
import material from "./dialog/material";
export default {
  props: ["rowId"],
  components: {
    Customer,
    Currency,
    PriceinfoId,
    PaymentTerms,
    SaleDept,
    SaleId,
    SettlementType,
    DiscountInfoId,
    RateType,
    ReceivingParty,
    SettlementParty,
    Payer,
    salesContract,
    material,
  },
  data() {
    return {
      activeName: "saleOrderEntity",
      dialog: false,
      counties: [],
      orgData: [], //创建组织弹窗列表
      orgSelect: [], //选中项
      orgTotal: "", //创建组织弹窗分页
      dialogType: "",
      dialogIndex: "",
      currentCom: "", //弹窗组件
      dialogTitle: "", //弹窗标题
      props: {},
      formObject: {
        materialDetailEntities: [],
        orderPurchaseTerms: [],
        saleCollectionPlanEntities: [],
        saleOrderDeliveryDetailEntities: [],
        saleOrderDeliveryEntity: {
          createBy: "",
          createTime: "",
          deliveryDown: "",
          deliveryType: "",
          deliveryUnit: "",
          deliveryUp: "",
          id: "",
          inventoryDept: "",

          materialCode: "",
          materialName: "",
          orderId: "",
          params: {},
          remark: "",
          searchValue: "",
          updateBy: "",
          updateTime: "",
        },
        saleOrderEntity: {
          businessType: "6",
          changeReason: "",
          createBy: "",
          createTime: "",
          currency: "",
          currencyName: "",
          customerId: "",
          customerName: "",
          delFlag: "",
          deliveryAddress: "",
          deliveryMethod: "",
          deptId: "",
          discountInfoId: "",
          discountInfoIdName: "",
          id: "",
          instanceId: "",
          isTax: "",
          kingDocCode: "",
          kingDocTypeId: "",
          margin: "",
          marginLevel: "",
          modelId: "",
          params: {},
          payer: "",
          payerName: "",
          paymentTerms: "",
          paymentTermsTitle: "",
          priceTax: "",
          priceinfoId: "",
          priceinfoIdName: "",
          rate: "",
          rateType: "",
          rateTypeName: "",
          receivingParty: "",
          receivingPartyName: "",
          remark: "",
          saleCode: "",
          saleDate: "",
          saleDept: "",
          saleDeptName: "",
          saleGroup: "",
          saleId: "",
          saleName: "",
          searchValue: "",
          settlementParty: "",
          settlementPartyName: "",
          settlementType: "",
          settlementTypeName: "",
          shippingAddress: "",
          shippingPerson: "",
          shippingPersonName: "",
          shippingPhone: "",
          sourceDocType: "",
          state: "",
          taxAmount: "",
          updateBy: "",
          updateTime: "",
          valueTax: "",
        },
        saleOrderLogisticsEntities: [],
      },

      invoiceTypeOptions: [
        {
          value: "1",
          label: "增值说专业用票",
        },
        {
          value: "2",
          label: "普通发票",
        },
      ],
      businessTypeOptions: [
        {
          label: "选项一",
          value: 1,
        },
        {
          label: "选项二",
          value: 2,
        },
      ],
      priceTaxOptions: [
        {
          label: "是",
          value: 0,
        },
        {
          label: "否",
          value: 1,
        },
      ],
      isTaxOptions: [
        {
          label: "是",
          value: "0",
        },
        {
          label: "否",
          value: "1",
        },
      ],
      materialType: [
        {
          label: "采购订单",
          value: 1,
        },
        {
          label: "销售订单",
          value: 2,
        },
        {
          label: "入库",
          value: 3,
        },
        {
          label: "出库",
          value: 4,
        },
        {
          label: "合同",
          value: 5,
        },
      ],
      rules: {
        saleOrderEntity: {
          kingDocTypeId: [
            // {
            //     required: true,
            //     message: "请输入单据类型",
            //     trigger: "blur",
            // },
          ],
          currencyName: [
            {
              required: true,
              message: "请输入结算币别",
              trigger: "blur",
            },
          ],
          saleDate: [
            {
              required: true,
              message: "请输入日期",
              trigger: "change",
            },
          ],
          businessType: [
            {
              required: true,
              message: "请输入业务类型",
              trigger: "change",
            },
          ],
          customerName: [
            {
              required: true,
              message: "请输入客户",
              trigger: "blur",
            },
          ],
        },

        saleOrderLogisticsEntities: {
          // logisiticsNumber: [
          //     {
          //         required: true,
          //         message: "请输入物流单号",
          //         trigger: "blur",
          //     },
          // ],
        },
      },
      documentTypeList: [],
    };
  },
  methods: {
    // 页签切换事件
    handleClick(tab, event) {},
    // 附件上传
    handleFileChange() {
      console.log("文件上传");
    },

    // 基础表单提交
    submit(cb) {
      this.$refs["formRef"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单
        if (this.formObject.docType) {
          this.formObject.docType =
            this.formObject.docType[this.formObject.docType.length - 1];
          this.formObject.docBusinessType =
            this.formObject.docType[this.formObject.docType.length - 1];
        }
        addSaleList(this.formObject).then((res) => {
          if (res.code === 200) {
            cb();
            this.$message({
              message: "新增成功！",
              type: "success",
            });
          }
        });
      });
    },

    // 基础表单取消
    formRest(basicFormRef) {
      this.$refs[basicFormRef].resetFields();
    },
    // 删除行
    handleDataDelete(index, row, type) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          if (type == "saleOrderDeliveryDetailEntities") {
            // 交货明细
            this.formObject.saleOrderDeliveryDetailEntities.splice(index, 1);
          } else if (type == "saleOrderLogisticsEntities") {
            //物流跟踪
            this.formObject.saleOrderLogisticsEntities.splice(index, 1);
          } else if (type === "orderPurchaseTerms") {
            //订单条款
            this.formObject.orderPurchaseTerms.splice(index, 1);
          } else if (type === "materialDetailEntities") {
            // 物料明细
            this.formObject.materialDetailEntities.splice(index, 1);
          } else if (type === "saleCollectionPlanEntities") {
            // 收款计划
            this.formObject.saleCollectionPlanEntities.splice(index, 1);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    //订单条款 添加新行
    addOrderDetails() {
      this.addOrderPurchaseTerms();
    },
    //物流跟踪 添加新行
    addLogistics() {
      this.addSaleOrderLogisticsEntities();
    },
    // 交货明细 添加新行
    addSale() {
      this.addSaleOrderDeliveryDetailEntities();
    },
    //物流明细 添加新行
    addDelivery() {
      this.addMaterialDetailEntities();
    },
    // 收款计划 添加新行
    addCollect() {
      this.addSaleCollectionPlanEntities();
    },
    //订单条款 添加行
    addOrderPurchaseTerms(index, row) {
      // 订单条款 obj
      let orderObj = {
        changeTime: "",
        createTime: "",
        describe: "",
        id: "",

        orderId: "",
        purchaseTermsId: "",
        type: "",
        userId: "",
      };
      this.formObject.orderPurchaseTerms.push(orderObj);
    },
    // 交货明细 添加行
    addSaleOrderDeliveryDetailEntities(index, row) {
      // 交货明细 obj
      let deliveryObj = {
        createBy: "",
        createTime: "",
        deliveryAddress: "",
        deliveryAddressDetail: "",
        deliveryDate: "",
        deliveryId: "",
        id: "",
        inAdvance: "",

        params: {},
        planDeliveryDate: "",
        remark: "",
        saleNum: "",
        saleUnit: "",
        searchValue: "",
        updateBy: "",
        updateTime: "",
      };
      this.formObject.saleOrderDeliveryDetailEntities.push(deliveryObj);
    },
    // 物流跟踪 添加行
    addSaleOrderLogisticsEntities(index, row) {
      // 物料跟踪 obj
      let logisticsObj = {
        createBy: "",
        createTime: "",
        deliveryTime: "",
        endAddress: "",
        id: "",

        logisiticsNumber: "",
        logisticsCompany: "",
        logisticsState: "",
        orderId: "",
        params: {},
        remark: "",
        searchValue: "",
        senderPhone: "",
        signTime: "",
        startAddress: "",
        type: "",
        updateBy: "",
        updateTime: "",
      };
      this.formObject.saleOrderLogisticsEntities.push(logisticsObj);
    },
    // 物料明细 添加行
    addMaterialDetailEntities(index, row) {
      // 物料明细 obj
      let materialObj = {
        amountMoney: "",
        batchNum: "",
        businessTaxCostPrice: "",
        changeTime: "",
        containsTaxPrice: "",
        createTime: "",
        deliveryAddress: "",
        deliveryDate: "",
        deliveryLocation: "",
        discountAmount: "",
        discountRate: "",
        executeStatus: "",
        id: "",
        inventoryId: "",
        inventoryNum: 0,
        inventoryUnit: "",
        isGiveaway: "",

        limit: 0,
        materialId: "",
        noTaxMoney: "",
        number: 0,
        page: 0,
        price: "",
        pricingNum: "",
        pricingUnit: "",
        purchaseUnit: "",
        ramarks: "",
        receivedFirstTicketsNum: "",
        receivingDept: "",
        relationId: "",
        requireDept: "",
        settlementDept: "",
        sourceDocCode: "",
        sourceDocType: "",
        sourceRelationId: "",
        supplierMaterialCode: "",
        supplierMaterialName: "",
        taxAmount: "",
        taxMoney: "",
        taxPrice: "",
        taxRate: "",
        token: "",
        totalAcceptanceAmount: "",
        totalAcceptanceRate: "",
        totalTaxPrice: "",
        type: 0,
        warehouseId: "",
        warehouseRegionId: "",
      };
      this.formObject.materialDetailEntities.push(materialObj);
    },
    // 收款计划 添加行
    addSaleCollectionPlanEntities(index, row) {
      // 收款计划 obj
      let collectObj = {
        actualPrepaymentDelivery: "",
        associationOrderNum: "",
        controlLink: "",
        createBy: "",
        createTime: "",
        dueTime: "",
        excessAmount: "",
        id: "",
        isPreReceipt: "",

        netReceiptsAmount: "",
        orderId: "",
        params: {},
        receivableAmount: "",
        receivableRatio: "",
        remark: "",
        searchValue: "",
        updateBy: "",
        updateTime: "",
      };
      this.formObject.saleCollectionPlanEntities.push(collectObj);
    },

    //添加新行
    addNewRow(type) {
      if (type === "orderPurchaseTerms") {
        this.addOrderDetails(); // 订单条款
      } else if (type === "saleOrderLogisticsEntities") {
        this.addLogistics(); // 物流跟踪
      } else if (type === "saleOrderDeliveryDetailEntities") {
        this.addSale(); //交货明细
      } else if (type === "materialDetailEntities") {
        this.addDelivery(); //物料明细
      } else if (type === "saleCollectionPlanEntities") {
        this.addCollect(); //收款计划
      }
    },
    // 处理弹窗弹出
    handleOpen() {
      const nameMap = {
        customer: () => {
          this.dialogTitle = "选择客户";
          this.currentCom = Customer;
        },
        currency: () => {
          this.dialogTitle = "选择结算币别";
          this.currentCom = Currency;
        },
        priceinfoId: () => {
          this.dialogTitle = "选择价目表";
          this.currentCom = PriceinfoId;
        },
        paymentTerms: () => {
          this.dialogTitle = "选择收款条件";
          this.currentCom = PaymentTerms;
        },
        saleDept: () => {
          this.dialogTitle = "选择销售部门";
          this.currentCom = SaleDept;
        },
        saleId: () => {
          this.dialogTitle = "选择销售员";
          this.currentCom = SaleId;
        },
        settlementType: () => {
          this.dialogTitle = "选择结算方式";
          this.currentCom = SettlementType;
        },
        discountInfoId: () => {
          this.dialogTitle = "选择折扣表";
          this.currentCom = DiscountInfoId;
        },
        rateType: () => {
          this.dialogTitle = "选择汇率类型";
          this.currentCom = RateType;
        },
        receivingParty: () => {
          this.dialogTitle = "选择收货方";
          this.currentCom = ReceivingParty;
        },
        settlementParty: () => {
          this.dialogTitle = "选择结算方";
          this.currentCom = SettlementParty;
        },
        payer: () => {
          this.dialogTitle = "选择付款方";
          this.currentCom = Payer;
        },
        salesContract: () => {
          this.dialogTitle = "选择销售合同明细";
          this.currentCom = salesContract;
        },
        material: () => {
          this.dialogTitle = "选择物料明细";
          this.currentCom = material;
        },
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 选择弹窗 item
    getSelectVal(val) {
      const nameMap = {
        customer: () => {
          this.formObject.saleOrderEntity.customerId = val[0].id;
          this.formObject.saleOrderEntity.customerName = val[0].customerName;
        },
        currency: () => {
          this.formObject.saleOrderEntity.currency = val[0].code;
          this.formObject.saleOrderEntity.currencyName = val[0].currencyName;
        },
        priceinfoId: () => {
          this.formObject.saleOrderEntity.priceinfoId = val[0].id;
          this.formObject.saleOrderEntity.priceinfoIdName = val[0].name;
        },
        paymentTerms: () => {
          this.formObject.saleOrderEntity.paymentTerms = val[0].id;
          this.formObject.saleOrderEntity.paymentTermsTitle = val[0].title;
        },
        saleDept: () => {
          this.formObject.saleOrderEntity.saleDept = val[0].deptId;
          this.formObject.saleOrderEntity.saleDeptName = val[0].deptName;
        },
        saleId: () => {
          this.formObject.saleOrderEntity.saleId = val[0].userId;
          this.formObject.saleOrderEntity.saleName = val[0].userName;
        },
        settlementType: () => {
          this.formObject.saleOrderEntity.settlementType = val[0].id;
          this.formObject.saleOrderEntity.settlementTypeName = val[0].title;
        },
        discountInfoId: () => {
          this.formObject.saleOrderEntity.discountInfoId = val[0].id;
          this.formObject.saleOrderEntity.discountInfoIdName = val[0].name;
        },
        rateType: () => {
          this.formObject.saleOrderEntity.rateType = val[0].id;
          this.formObject.saleOrderEntity.rateTypeName = val[0].name;
        },
        receivingParty: () => {
          this.formObject.saleOrderEntity.receivingParty = val[0].id;
          this.formObject.saleOrderEntity.receivingPartyName =
            val[0].customerName;
        },
        settlementParty: () => {
          this.formObject.saleOrderEntity.settlementParty = val[0].id;
          this.formObject.saleOrderEntity.settlementPartyName =
            val[0].customerName;
        },
        payer: () => {
          this.formObject.saleOrderEntity.payer = val[0].id;
          this.formObject.saleOrderEntity.payerName = val[0].customerName;
        },
        salesContract: () => {
          this.formObject.materialDetailEntities.splice(this.dialogIndex, 1);
          val.forEach((e) => {
            const obj = this.defaultDetailObj();
            for (const key in obj) {
              if (e[key]) {
                obj[key] = e[key];
              }
            }
            this.formObject.materialDetailEntities.push(obj);
          });
        },
        material: () => {
          this.formObject.materialDetailEntities.splice(this.dialogIndex, 1);
          val.forEach((e) => {
            const obj = this.defaultDetailObj();
            for (const key in obj) {
              if (e[key]) {
                obj[key] = e[key];
              }
            }
            this.formObject.materialDetailEntities.push(obj);
          });
        },
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    //点击选择dialog中的一条数据回显
    addDialog(type, index) {
      this.dialog = true;
      this.dialogType = type;
      this.dialogIndex = index;
      this.handleOpen();
    },
    //默认获取省列表
    getProvince(parentId) {
      // 查询省份
      getAreaList({ parentId: parentId }).then((res) => {
        this.provinces = res.rows;
      });
    },
    //点击省份获取城市列表
    getCity(parentId) {
      this.formObject.cityId = "";
      this.formObject.countyId = "";
      this.counties = [];
      // 查询省份
      getAreaList({ parentId: parentId }).then((res) => {
        this.cities = res.rows;
      });
    },
    //点击城市获取区县列表
    getCounty(parentId) {
      this.formObject.countyId = "";
      // 查询省份
      getAreaList({ parentId: parentId }).then((res) => {
        this.counties = res.rows;
      });
    },
    // 创建组织
    selectOrg() {
      this.showOrg = true;
      let level = 1;
      listDept({ level }).then((res) => {
        if (res.code === 200) {
          this.orgData = res.data;
        }
        return;
      });
    },
    // 创建组织item
    selectOrgItem(val) {
      if (val.length === 1) {
        this.orgSelect = val;
        this.showOrg = false;
      }
    },
    //获取单据类型
    getDocTypeListApi() {
      getDocTypeList({ parentCode: "All" }).then((res) => {
        if (res.code === 200) {
          this.documentTypeList = res.rows;
        }
      });
    },
    //下拉类型选择
    handleCommand(val) {
      this.dialogType = val;
      this.dialog = true;
      this.handleOpen();
      this.activeName = "materialDetailEntities";
    },
    defaultDetailObj() {
      return {
        amountMoney: "",
        batchNum: "",
        businessTaxCostPrice: "",
        changeTime: "",
        changeType: "",
        createTime: "",
        deliveryAddress: "",
        deliveryDate: "",
        deliveryLocation: "",
        discountAmount: "",
        discountRate: "",
        executeStatus: "",
        id: "",
        inventoryId: "",
        inventoryNum: 0,
        inventoryUnit: "",
        isGiveaway: true,

        limit: 0,
        material: {
          allowAsset: "",
          allowInventory: "",
          allowOutsource: "",
          allowProduce: "",
          allowPurchase: "",
          allowSale: "",
          barCode: "",
          brand: "",
          businessType: "",
          configurationProduction: "",
          costPriceRatio: "",
          createBy: "",
          createTime: "",
          dataState: "",
          defaultTaxRate: "",
          deptId: "",
          disableBy: "",
          examineBy: "",
          examineTime: "",
          grossWeight: "",
          heightStr: "",
          id: "",
          imgUrl: "",
          instanceId: "",
          inventoryType: "",
          isChange: "",

          kit: "",
          lengthStr: "",
          materialCode: "",
          materialDesc: "",
          materialGroup: "",
          materialInventoryEntity: {
            batchInfo: "",
            batchRule: "",
            checkCycle: "",
            convertDirection: "",
            costUnit: "",
            createBy: "",
            createTime: "",
            currency: "",
            day: "",
            economicOrderingBatch: "",
            id: "",
            inventoryUnit: "",
            isBatch: "",
            isCheck: "",
            isLock: "",
            isMaxInventory: "",
            isMinInventory: "",
            isOrderGoods: "",
            isSafeInventory: "",
            isTrueCheck: "",
            materialId: "",
            maxInventoyNum: "",
            minInventoryNum: "",
            orderGoodsNum: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            qualityManage: "",
            qualityNum: "",
            qualityUnit: "",
            referenceCost: "",
            remark: "",
            safeInventoryNum: "",
            searchValue: "",
            serviceLife: "",
            standardNumber: "",
            supportUnit: "",
            updateBy: "",
            updateTime: "",
            warePosition: "",
            warehouseCode: "",
          },
          materialName: "",
          materialPlanAttributeEntity: {
            createBy: "",
            createTime: "",
            fAllowPartDelay: "",
            fBaseVarLeadTimeLotSize: "",
            fBaseVarLeadTimeLotSizeUnit: "",
            fCanDelayDays: 0,
            fCanLeadDays: 0,
            fCheckLeadTime: 0,
            fCheckLeadTimeType: "",
            fDelayExtendDay: 0,
            fFixLeadTime: 0,
            fFixLeadTimeType: "",
            fIncreaseQty: 0,
            fIncreaseQtyUnit: "",
            fIsMrpComBill: "",
            fIsMrpComReq: "",
            fLeadExtendDay: 0,
            fMaxPoqty: 0,
            fMfgPolicyId: "",
            fMinPoqty: 0,
            fMinPoqtyUnit: "",
            fOrderIntervalTime: 0,
            fOrderIntervalTimeType: "",
            fOrderPolicy: "",
            fPlanBatchSplitQty: "",
            fPlanBatchSplitQtyUnit: "",
            fPlanGroupId: "",
            fPlanIdent: "",
            fPlanIntervalsDays: 0,
            fPlanOffsetTime: 0,
            fPlanOffsetTimeType: "",
            fPlanSafeStockQty: 0,
            fPlanSafeStockQtyUnit: "",
            fPlanTimeZone: 0,
            fPlanWorkshop: "",
            fPlanerId: "",
            fPlanningStrategy: "",
            fProScheTrackId: "",
            fProductLine: "",
            fRequestTimeZone: 0,
            fSupplySourceId: "",
            fVarLeadTime: 0,
            fVarLeadTimeLotSize: "",
            fVarLeadTimeLotSizeUnit: "",
            fVarLeadTimeType: "",
            fWriteOffQty: "",
            fWriteOffQtyUnit: "",
            id: "",
            materialId: "",
            maxPoqtyUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProcureEntity: {
            agentProcure: "",
            barCodeRule: "",
            createBy: "",
            createTime: "",
            dayProduction: 0,
            dayProductionUnit: "",
            defaultSupplier: "",
            defunctProductionLine: "",
            expenseItem: "",
            id: "",
            isControl: "",
            isDayProduction: "",
            isMaterialReturn: "",
            isQuota: "",
            isReq: "",
            materialId: "",
            minPackNum: "",
            minSpiltNum: 0,
            outsourcePricingUnit: "",
            outsourceType: "",
            outsourceUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            procureGroup: "",
            procureId: "",
            procurePricingUnit: "",
            procureType: "",
            procureUnit: "",
            quotaMode: "",
            remark: "",
            repeatPutNum: "",
            searchValue: "",
            takeOverDelay: 0,
            takeOverDown: "",
            takeOverLead: 0,
            takeOverUp: "",
            updateBy: "",
            updateTime: "",
          },
          materialProductEntity: {
            createBy: "",
            createTime: "",
            deptId: "",
            fBackFlushType: "",
            fConsumVolatility: "",
            fDefaultLineId: "",
            fDefaultRouting: "",
            fFinishReceiptOverRate: "",
            fFinishReceiptShortRate: "",
            fIsCompleteSet: "",
            fIsEnableSchedule: "",
            fIsKitting: "",
            fIsMainPrd: "",
            fIsMinissueQty: "",
            fIsProductLine: "",
            fIsSNCarryToParent: "",
            fIssueType: "",
            fMdlId: "",
            fMdlMaterialId: "",
            fMinissueQty: 0,
            fMinissueUnitId: "",
            fOrgTrustBillType: "",
            fOverControlMode: "",
            fPerUnitStandHour: "",
            fPickBinId: "",
            fPickStockId: "",
            fProduceBillType: "",
            fProduceUnitId: "",
            fStandHourUnitId: "",
            fStdLaborPrePareTime: "",
            fStdLaborProcessTime: "",
            fStdMachinePrepareTime: "",
            fStdMachineProcessTime: "",
            fWorkShopId: "",
            fbkfltime: "",
            fbomunitid: "",
            ffixloss: "",
            fisecn: "",
            flosspercent: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProperty: "",
          materialQualityEntity: {
            createBy: "",
            createTime: "",
            fCheckDelivery: "",
            fCheckEntrusted: "",
            fCheckIncoming: "",
            fCheckOther: "",
            fCheckProduct: "",
            fCheckReturn: "",
            fCheckStock: "",
            fCheckSubFtnMtrl: "",
            fEWLeadDay: "",
            fEnableCyclistQCSTK: "",
            fEnableCyclistQcstkew: "",
            fFirstQCControlType: "",
            fIncQcSchemeId: "",
            fIncSampSchemeId: "",
            fInspectGroupId: "",
            fInspectorId: "",
            fIsFirstInspect: "",
            fStockCycle: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialSaleEntity: {
            allowReleaseOrder: "",
            allowReturns: "",
            atpCheck: "",
            controlSurpassUnit: "",
            createBy: "",
            createTime: "",
            dropOutCount: "",
            fisReturnPart: "",
            fisaftersale: "",
            fisproductfiles: "",
            fiswarranted: "",
            fwarranty: "",
            fwarrantyunitid: "",
            id: "",
            isFavourableTax: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            saleDownPrice: "",
            saleGroup: "",
            saleOutbound: "",
            salePricingUnit: "",
            saleUnit: "",
            searchValue: "",
            startOrderNum: 0,
            surpassDown: "",
            surpassUp: "",
            taxType: "",
            taxTypeCode: "",
            updateBy: "",
            updateTime: "",
          },
          mnemonicCode: "",
          model: "",
          modelId: "",
          netWeight: "",
          oldMaterialCode: "",
          pageNo: 0,
          pageSize: 0,
          params: {},
          reasonForDisable: "",
          remark: "",
          searchValue: "",
          sizeUnit: "",
          state: "",
          subItems: "",
          taxType: "",
          typeName: "",
          unit: "",
          updateBy: "",
          updateTime: "",
          volume: "",
          weightUnit: "",
          wideStr: "",
        },
        materialCode: "",
        materialId: "",
        netAmount: "",
        noTaxMoney: "",
        number: 0,
        orderDelivery: {
          batchNum: "",
          bomVer: "",
          changeTime: "",
          controlDeliveryNum: true,
          controlDeliveryTime: true,
          createTime: "",
          deliveryDelayDay: "",
          deliveryDown: "",
          deliveryEarlyTime: "",
          deliveryLatestTime: "",
          deliveryLeadDay: "",
          deliveryUp: "",
          id: "",

          materialId: "",
          materialName: "",
          orderDeliveryDetails: [
            {
              address: "",
              changeTime: "",
              confirmComment: "",
              confirmNum: "",
              confirmTime: "",
              createTime: "",
              deliveredNum: "",
              deliveryTime: "",
              id: "",

              location: "",
              num: "",
              orderDeliveryId: "",
              orderId: "",
              planUnit: "",
              surplusNum: "",
              userId: "",
            },
          ],
          orderId: "",
          receiveDept: "",
          receiveOrg: "",
          requireDept: "",
          requireOrg: "",
          supplierBatch: "",
          supportAttr: "",
          userId: "",
        },
        orderFinanceDetail: {
          changeTime: "",
          createTime: "",
          discountAmount: "",
          discountRate: "",
          entryPriceInfo: "",
          id: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          netPrice: "",
          orderId: "",
          priceCeiling: "",
          priceCoefficient: "",
          priceFloor: "",
          pricingNum: "",
          pricingUnit: "",
          settlementDept: "",
          systemPricing: "",
          taxRate: "",
          unitPriceDiscount: "",
          userId: "",
        },
        orderOther: {
          businessClose: "",
          businessFreeze: "",
          businessProcess: "",
          businessStop: "",
          changeTime: "",
          contractsCode: "",
          createTime: "",
          freezeName: "",
          freezeTime: "",
          id: "",
          inventoryReturnNum: "",
          isPlanConfirm: "",
          isQuotaGeneration: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          materialReceivedReturnNum: "",
          orderId: "",
          planTrackingCode: "",
          requireDocCode: "",
          requireDocLineCode: "",
          requireFrom: "",
          requireTrackingCode: "",
          sourceDocCode: "",
          sourceDocType: "",
          stopName: "",
          stopTime: "",
          surplusInboundNum: "",
          surplusMaterialReceivedNum: "",
          totalInboundNum: "",
          totalMaterialReceivedNum: "",
          totalMaterialReturnNum: "",
          updateFlag: "",
          userId: "",
        },
        originalContainsTaxPrice: "",
        originalNumber: "",
        page: 0,
        parentMaterial: "",
        price: "",
        pricingNum: "",
        pricingUnit: "",
        purchaseUnit: "",
        ramarks: "",
        receivedFirstTicketsNum: "",
        receivingDept: "",
        relationId: "",
        requireDept: "",
        settlementDept: "",
        sourceDocCode: "",
        sourceDocType: "",
        sourceRelationId: "",
        supplierMaterialCode: "",
        supplierMaterialName: "",
        taxAmount: "",
        taxMoney: "",
        taxPrice: "",
        taxRate: "",
        token: "",
        totalAcceptanceAmount: "",
        totalAcceptanceRate: "",
        totalTaxPrice: "",
        type: 0,
        warehouseId: "",
        warehouseRegionId: "",
      };
    },
  },
  created() {
    this.getDocTypeListApi();
    // 查询中国下属省份
    this.getProvince("20230705392153575054249984");
    if (this.rowId) {
      getOrderDetail(this.rowId).then((res) => {
        if (res.code === 200) {
          this.formObject = res.data;
        }
      });
    }
    this.props = {
      lazy: true,
      lazyLoad(node, resolve) {
        const { level } = node;
        const parentCode = level >= 1 ? node.value : "All";
        getDocTypeList({ parentCode }).then((res) => {
          if (res.code === 200) {
            this.documentTypeList = res.rows;
            const nodes = res.rows.map((item) => ({
              value: item.docCode,
              label: item.title,
            }));
            // 通过调用resolve将子节点数据返回，通知组件数据加载完成
            resolve(nodes);
          }
        });
      },
    };
  },
};
</script>
<style lang="scss" scoped>
// .add {
//   padding: 15px;
// }
.panel-title {
  font-size: 18px;
  color: #37474f;
  font-weight: 500;
  text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

::v-deep .el-form-item__content {
  margin-left: 0;
}

.main-responsible {
  font-size: 14px;
  font-weight: 550;
  color: #263238;
  position: relative;
  text-indent: 15px;
}
</style>
